//
//  SetView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2024/12/26.
//

import SwiftUI

//公告
struct NotifyView: View {
    @StateObject var viewModel = NotifyViewModel()
    
    var body: some View {
        ZStack{
            if !viewModel.status.isEmpty {
                HomeEmptyView(text1: viewModel.status)
                    .frame(maxWidth: .infinity,maxHeight: .infinity)
            } else {
                ScrollView {
                    // 数据列表
                    ForEach(viewModel.items) { item in
                        NotifyItemView(item: item)
                    }
                    
                    LoadMoreFooter(refreshing: $viewModel.footerRefreshing, action: {
                        viewModel.getData(false)
                    }) {
                        LoadMoreView(noMore: viewModel.noMore, footerRefreshing: viewModel.footerRefreshing)
                    }
                    .noMore(viewModel.noMore)
                    .preload(offset: 10)
                }
                .enableRefresh()
                .onAppear {
                    if !viewModel.isInit {
                        viewModel.getData(true)
                        viewModel.isInit = true
                    }
                }
            }
        }.navigationTitle("公告")
            .background(.bg)
        
    }
}

//#Preview {
//    SetView()
//}


//定义预览提供者
struct Notify_Previews: PreviewProvider {
    static var previews: some View {
        //使用预览共享配置
        configurePreviewEnvironment(for: NotifyView())
    }
}
